﻿#include "LineEdit_TurnTableAcceleration.h"

#include <qregexp.h>
#include <qvalidator.h>

LineEdit_TurnTableAcceleration::LineEdit_TurnTableAcceleration(QWidget *parent)
	: QLineEdit(parent)
{

	QRegExp regExp2("^(\\d+)(\\.\\d+)?$");
	setValidator(new QRegExpValidator(regExp2,this));
	connect(this, &LineEdit_TurnTableAcceleration::editingFinished, this, &LineEdit_TurnTableAcceleration::slot_accelerationLineEditFinished);
	slot_updatePlaceHolder();
}

LineEdit_TurnTableAcceleration::~LineEdit_TurnTableAcceleration()
{
}
float LineEdit_TurnTableAcceleration::getAcceleration()
{
	QString value = text();
	if (value.isEmpty())
	{
		return turnTableAccelerationLowerLimit;
	}
	else
	{
		return value.toFloat();
	}
}
void LineEdit_TurnTableAcceleration::setAcceleration(float acceleration)
{
	setText(QString::number(acceleration));
	slot_accelerationLineEditFinished();
}
void LineEdit_TurnTableAcceleration::slot_accelerationLineEditFinished()
{
	QString acceleration = text();
	if (acceleration.isEmpty())
	{
		setText(QString::number(turnTableAccelerationLowerLimit));
		return;
	}
	float acceleration1 = acceleration.toFloat();
	if (acceleration1 > turnTableAccelerationUpperLimit)
	{
		setText(QString::number(turnTableAccelerationUpperLimit));
	}
	else if (acceleration1 < turnTableAccelerationLowerLimit)
	{
		setText(QString::number(turnTableAccelerationLowerLimit));
	}
}
void LineEdit_TurnTableAcceleration::slot_updatePlaceHolder()
{
	setPlaceholderText(QString::number(turnTableAccelerationLowerLimit) + QStringLiteral("至") + QString::number(turnTableAccelerationUpperLimit));
}

float LineEdit_TurnTableAcceleration::getTurnTableAccelerationUpperLimit()
{
	return turnTableAccelerationUpperLimit;
}
void LineEdit_TurnTableAcceleration::setTurnTableAccelerationUpperLimit(float  turnTableAccelerationUpperLimit)
{
	this->turnTableAccelerationUpperLimit = turnTableAccelerationUpperLimit;
	slot_updatePlaceHolder();
}
float LineEdit_TurnTableAcceleration::getTurnTableAccelerationLowerLimit()
{
	return turnTableAccelerationLowerLimit;
}
void LineEdit_TurnTableAcceleration::setTurnTableAccelerationLowerLimit(float turnTableAccelerationLowerLimit)
{
	this->turnTableAccelerationLowerLimit = turnTableAccelerationLowerLimit;
	slot_updatePlaceHolder();
}
int LineEdit_TurnTableAcceleration::getAccuracy()
{
	return accuracy;
}
void LineEdit_TurnTableAcceleration::setAccuracy(int accuracy)
{
	this->accuracy = accuracy;
}
